using System;

namespace DanMuHelper.Tools
{
    public abstract class SingletonCSharp<T> where T : class, new()
    {
        private static T m_Instance;
        private static object lockHelper = new object();

        public static T Instance
        {
            get
            {
                if (m_Instance == null)
                {
                    lock (lockHelper)
                    {
                        if (m_Instance == null)
                        {
                            m_Instance = new T();
                        }
                    }
                }
                return m_Instance;
            }
            set { m_Instance = null; }
        }

        protected SingletonCSharp()
        {
            if (m_Instance != null)
            {
                throw new InvalidOperationException("Can't create singleton instance more than once.");
            }
        }
    }
}